package com.jinbo.footmessage.serverInf;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.RatingBar;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.jinbo.footmessage.R;
import com.jinbo.footmessage.httpbean.CommentBean;
import com.jinbo.footmessage.httpretrofit.HttpProtocolFactory;

import java.util.List;

import de.hdodenhof.circleimageview.CircleImageView;


/**
 * Created by jinbo on 2015/8/19.
 */
public class CommentItemListViewAdapter extends BaseAdapter {
    List<CommentBean> comments;

    static class ViewHolder {
        CircleImageView head;
        TextView name;
        TextView content;
        TextView projetct_name;
        TextView time;
        RatingBar star;
    }

    private Context context;

    public CommentItemListViewAdapter(Context context, List<CommentBean> datalist) {//ArrayList<CommentBean> datalist) {
        this.context = context;
        comments=datalist;
    }

   void setcomments( List<CommentBean> datalist)
    {
        this.comments=datalist;
    }
    

    @Override
    public int getCount() {
            // TODO Auto-generated method stub*//*
            if (comments != null) {
                return comments.size();
            }
        return 0;
    }

    @Override
    public Object getItem(int position) {
        // TODO Auto-generated method stub
            if (comments != null) {
                return comments.get(position);
            }
        return null;
    }

    @Override
    public long getItemId(int position) {
        // TODO Auto-generated method stub
        return position;
    }
    @Override

    public View getView(final int position, View convertView, ViewGroup arg2) {
        ViewHolder holder = null;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.list_comment_item, null);
            holder = new ViewHolder();

            holder.head=(CircleImageView)convertView.findViewById(R.id.head);
            holder.name=(TextView)convertView.findViewById(R.id.user_name);
            holder.content=(TextView)convertView.findViewById(R.id.content);
            holder.projetct_name=(TextView)convertView.findViewById(R.id.project_name);
            holder.star=(RatingBar)convertView.findViewById(R.id.star);
            holder.time=(TextView)convertView.findViewById(R.id.time);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        Glide.with(context)
                .load(HttpProtocolFactory.HOST_URL_USER+comments.get(position).user_head)
                        // .placeholder(R.mipmap.ic_launcher)
                        // .crossFade()
                .into(holder.head);
       holder.name.setText(comments.get(position).user_name);
        holder.content.setText(comments.get(position).content);
        holder.projetct_name.setText(comments.get(position).project_name);
        holder.star.setRating((float)comments.get(position).star);
        holder.time.setText(comments.get(position).time);
        return convertView;
    }
}
